<?php
/**
 * Description of sfGuardDeleteUserTask
 *
 * @author Bartpab
 */
class sfGuardDeleteUserTask extends sfBaseTask {
    protected function configure(){
        $this->addOptions(array(
           new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The Application', 'frontend'),
           new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The Environment', 'prod'),
        ));
        $this->addArguments(array(
            new sfCommandArgument("username", null, sfCommandArgument::REQUIRED)
        ));
        $this->namespace = "user";
        $this->name = "delete";
        $this->briefDescription = 'Delete an user';
        $this->detailedDescription = <<<EOF
            The [user:delete|INFO] task deletes an user from the database:
            [./symfony user:delete username --env=prod |INFO]
EOF;
        }
        protected function execute($arguments = array(), $options = array()){
            $databaseManager = new sfDatabaseManager($this->configuration);
            $q = Doctrine_Query::create()->delete("sfGuardUser u")->where("username = ?", $arguments["username"]);
            if($q->execute())
                $this->logSection("Doctrine", sprintf("Removed the user %s", $arguments["username"]));
            else
                $this->logSection("Doctrine", sprintf("Failed to remove the user %s", $arguments["username"]));
        }

}
?>
